﻿#region Using Directives

using System;
using System.Web.Caching;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Serialization;
using QuickDev.Common.Caching.Manager;

using QuickDev.SQLServerDAL;
using QuickDev.Model;

#endregion

namespace QuickDev.Caching
{
    public class SiteSettingsCache
    {
        #region Constants

        private const string SiteSettingsCacheKey = "_SiteSettings_CacheKey";

        #endregion

        #region Refresh Cache

        /// <summary>
        /// Removes the Object Info from the cache.
        /// This will make that the Object should reinsert itself on the next page request
        /// </summary>
        /// <param name="key">The key.</param>
        public static void RemoveSiteSettingsCacheKeyFromCache()
        {
            CacheHelper.RemoveCacheObject<string>( SiteSettingsCacheKey );
        }

        #endregion

        #region SiteSettings.GetModel() Method

        /// <summary>
        /// public SiteSettings GetModel()
        /// </summary>
        /// <returns>SiteSettings model</returns>
        public static SiteSettings GetCachedModel()
        {
            return CacheHelper.CacheObject<SiteSettings>
            (
                delegate
                {
                    return SiteSettingDAL.Load();
                },
                SiteSettingsCacheKey,
                CacheLength.GetLongCacheTime,
                CacheItemPriority.High
            );
        }
        #endregion
    }
}
